<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from './bus';
export default {
    data() {
        return {
            collapse: false,
            items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'dashboard',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-lx-cascades',
                    index: 'table',
                    title: '报表统计'
                },
                {
                    icon: 'el-icon-lx-calendar',
                    index: '3',
                    title: '仓库管理',
                    subs: [
                        {
                            index: 'addWarehouse',
                            title: '子仓库管理'
                        },
                        {
                            index: 'warehousingManage',
                            title: '入库管理'
                        },
                        {
                            index: 'outInf',
                            title: '出库管理'
                        },
                        {
                            index: 'returnList',
                            title: '退货管理'
                        },
                        {
                            index: 'loss',
                            title: '损耗管理'
                        },
                        {
                            index: 'check',
                            title: '统计报表'
                        },
                        {
                            index: 'inventory',
                            title: '开始盘点'
                        },

                    ]
                },
                {
                    icon: 'el-icon-pie-chart',
                    index: 'supplierManage',
                    title: '供应商管理'
                },
                {
                    icon: 'el-icon-rank',
                    index: '6',
                    title: '财务管理',
                    subs: [
                        {
                            index: '',
                            title: '工资管理'
                        },
                        {
                            index: '',
                            title: '绩效管理'
                        }
                    ]
                },

                {
                    icon: 'el-icon-lx-newsfill',
                    index: 'AccMangement',
                    title: '运营商管理',

                },
                {
                    icon: 'el-icon-lx-calendar',
                    index: '1',
                    title: '审批管理',
                    subs: [
                        {
                            index: 'OperatonApplication',
                            title: '运营商审批'
                        },
                        {
                            index: 'SupplierApplication',
                            title: '供应商审批'
                        },
                        {
                            index: 'LossApplication',
                            title: '损耗审批'
                        },
                        {
                            index: 'ReturnApproval',
                            title: '退货审批'
                        },{
                            index: 'VmExamine',
                            title: '售货机审核'
                        }
                    ]
                },
                {
                    icon: 'el-icon-lx-peoplefill',
                    index: '2',
                    title: '用户管理',
                    subs: [
                        {
                            index: 'Home',
                            title: '后台用户管理'
                        },
                        {
                            index: '',
                            title: '消费者管理'
                        },{
                            index: 'Role',
                            title: '角色管理'
                        },{
                            index: '',
                            title: '菜单管理'
                        },{
                            index: '',
                            title: '权限分配'
                        },
                    ]
                }, {
                    icon: 'el-icon-lx-mobile',
                    index: '4',
                    title: '售货机配置',
                    subs: [
                        {
                            index: 'VedingMachine',
                            title: '售货机管理'
                        },
                        {
                            index: 'map',
                            title: '地图'
                        },{
                            index: '',
                            title: '区域配置'
                        },
                    ]
                },{
                    icon:'el-icon-lx-goods',
                    index:'Order',
                    title: '订单查询'
                }
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
